import { baseUrlApi, requestClient, type Result } from '#/api/request';

export interface RoutesData {
  full_url: string; // 原始网址
  url: string; // 显示网址
  status?: number; // 状态
  id?: number;
}

/**
 * 后台首页菜单列表,常用于后台首页左侧菜单
 * @returns
 */
export const getAsyncRoutes = () => {
  return requestClient.get<Result>(baseUrlApi('/admin/home/menus'));
};

/** 路由列表 */
export const getRoutes = () => {
  return requestClient.get<Result>(baseUrlApi('/admin/routes'));
};

/**
 * 添加路由
 * @param data
 * @returns
 */
export const postRoutes = (data?: RoutesData) => {
  return requestClient.post<Result>(baseUrlApi('/admin/routes'), data);
};

/**
 * 获取路由信息
 * @param id
 * @returns
 */
export const getRoutesInfo = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/routes/${id}`));
};

/**
 * 编辑路由
 * @param id
 * @param data
 * @returns
 */
export const putRoutes = (id: number, data?: RoutesData) => {
  return requestClient.put<Result>(baseUrlApi(`/admin/routes/${id}`), data);
};

/**
 * 删除路由
 * @param id
 * @returns
 */
export const deleteRoutes = (id: number) => {
  return requestClient.delete<Result>(baseUrlApi(`/admin/routes/${id}`));
};

/**
 * 切换路由显示状态
 * @param id
 * @returns
 */
export const postRoutesToggle = (id: number) => {
  return requestClient.post<Result>(baseUrlApi(`/admin/routes/${id}/toggle`));
};

/**
 * 设置路由显示状态
 * @param id 路由id
 * @param status 路由显示状态,0:隐藏;1:显示
 * @returns
 */
export const postRoutesStatus = (id: number, status: number) => {
  return requestClient.put<Result>(
    baseUrlApi(`/admin/routes/${id}/status/${status}`),
  );
};

/**
 * 路由排序
 * @param data
 * @returns
 */
export const postRoutesListOrder = (data: { list_orders: object }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/routes/list/order`),
    data,
  );
};

/** 应用路由规则列表 */
export const getRoutesAppUrls = () => {
  return requestClient.get<Result>(baseUrlApi('/admin/routes/app/urls'));
};
